<template>
  <div v-loading="loading" class="app-container">
    <div class="head-container">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item name="1">
          <template slot="title">
            <i class="el-icon-search" />搜索栏
          </template>
          <el-form :model="params" class="searchform" :inline="true" size="mini" label-width="auto">
            <el-form-item label="正确示例">
              <el-input v-model="params.correctEx" placeholder="模糊匹配" clearable style="width: 200px;" />
            </el-form-item>
            <el-form-item label="错误示例">
              <el-input v-model="params.errorEx" placeholder="模糊匹配" clearable style="width: 200px;" />
            </el-form-item>
            <el-form-item>
              <el-button size="mini" type="primary" style="float:right;margin-right:0px;" icon="el-icon-refresh" round @click="resetForm">重置</el-button>
              <el-button size="mini" type="primary" style="float:right;margin-right:0px;" icon="el-icon-search" round @click="toQuery">查询</el-button>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
    <div style="padding-top:5px">
      <el-button v-if="hasRole(['R017001'])" size="mini" type="primary" style="float:right;margin-bottom:5px;margin-left:0px;" icon="el-icon-plus" round @click="doSave({})">新增</el-button>
      <!-- <el-button size="mini" type="primary" style="float:right;margin-left:0px;" icon="el-icon-edit" round @click="doClearSelection">取消选择</el-button> -->
      <el-table ref="dataTab" :data="data" :row-key="getRowKeys" stripe size="small" border style="width: 100%;" @header-dragend="colChange" @selection-change="handleSelectionChange">
        <!-- <el-table-column :reserve-selection="true" type="selection" align="center" width="55" /> -->
        <el-table-column :show-overflow-tooltip="true" label="正确示例" prop="correctEx" :width="colWidths.correctEx" />
        <el-table-column :show-overflow-tooltip="true" label="错误示例" prop="errorEx" :width="colWidths.errorEx" />
        <el-table-column :show-overflow-tooltip="true" label="是否启用" prop="validateFlag" :width="colWidths.validateFlag" />
        <el-table-column :show-overflow-tooltip="true" label="创建时间" prop="createdTime" :width="colWidths.createdTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createdTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="最后修改人" prop="updatedBy" :width="colWidths.updatedBy" />
        <el-table-column :show-overflow-tooltip="true" label="最后修改时间" prop="updatedTime" :width="colWidths.updatedTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updatedTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" round @click="doSave(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <el-pagination
        :total="total"
        :current-page.sync="currentPage"
        :page-sizes="[10,50,100,500]"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"
      />
    </div>
    <writeGuideForm ref="writeGuideForm" :parent="this" />
  </div>
</template>

<script>
import initData from '@/utils/initData'
import { parseTime } from '@/utils/index'
import writeGuideForm from './info'

export default {
  components: { writeGuideForm },
  mixins: [initData],
  data() {
    return {
      loading: false,
      activeName: '1',
      ids: []
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    beforeInit() {
      this.url = '/writeGuide/queryList'
      this.params.pageNum = this.page
      this.params.pageSize = this.size
      return true
    },
    // 查询
    toQuery() {
      this.page = 0
      this.currentPage = 1
      this.init()
      this.doClearSelection()
    },
    // 查询栏重置触发
    resetForm() {
      this.params = {}
    },
    // 列表多选框触发
    handleSelectionChange(val) {
      this.ids = []
      val.forEach(item => {
        this.ids.push(item.id)
      })
    },
    // 翻页选择row的key值
    getRowKeys(row) {
      return row.id
    },
    // 清空选择项
    doClearSelection() {
      this.$refs.dataTab.clearSelection()
    },
    // 编辑指引内容
    doSave(obj) {
      this.$refs.writeGuideForm.writeGuide = obj
      this.$refs.writeGuideForm.dialog = true
    }
  }
}
</script>
